package com.sec.android.app.myfiles.launch;

import android.app.Activity;
import android.content.Intent;
import android.text.TextUtils;

import com.sec.android.app.myfiles.facade.MyFilesFacade;
import com.sec.android.app.myfiles.info.AppConstants;
import com.sec.android.app.myfiles.info.AppFeatures;
import com.sec.android.app.myfiles.module.abstraction.FileRecord;
import com.sec.android.app.myfiles.navigation.NavigationInfo;

public class HandlePathPickerImp extends AbsHandleLaunchImp {
    @Override
    public boolean isMyJob(Intent intent) {
        return (AppConstants.Action.ACTION_PICK_SELECT_PATH.equals(intent.getAction()) ||
                AppConstants.Action.PICK_DOWNLOADS.equals(intent.getAction()));
    }

    @Override
    public boolean _handleStart(int processId, Activity activity, Intent intent) {
        FileRecord homePath;
        String path = intent.getStringExtra(AppConstants.MyFilesExtras.URI);
        if (!TextUtils.isEmpty(path)) {
            homePath = FileRecord.createFileRecord(FileRecord.StorageType.Local, path);
        } else {
            if (AppFeatures.isTabletUIMode()) {
                homePath = FileRecord.createFileRecord(FileRecord.StorageType.Local,
                        AppConstants.StoragePath.INTERNAL_ROOT);
            } else {
                homePath = FileRecord.createFileRecord(FileRecord.StorageType.Home, "");
            }
        }

        boolean isDownload = AppConstants.Action.PICK_DOWNLOADS.equals(intent.getAction());
        MyFilesFacade.launchPicker(processId, homePath, NavigationInfo.NavigationMode.Select_destination_path, isDownload);
        return true;
    }
}
